package com.syg.servlet02;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

/**
 * 使用outputstream流向客户端输出数据
 */
@WebServlet("/respOut")
public class _03_ResponseOutPutStream extends HttpServlet{
    @Override
    public void init() throws ServletException {
        //读取初始化参数
        String initParam = this.getInitParameter("resINIT");
        System.out.println(initParam);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String initParam = this.getInitParameter("resINIT");
        System.out.println(initParam);
        OutputStream out = resp.getOutputStream();
        String data = "南京大屠杀";
        out.write(data.getBytes());
        String dataStr = "向浏览器输出数字：";
        out.write((1+"").getBytes());
    }

}
